import 'package:flutter/material.dart';
import 'package:flutter/services.dart';

class NativePage extends StatelessWidget {
  final SystemUiOverlayStyle _style =
  SystemUiOverlayStyle(statusBarColor: Colors.transparent);

  @override
  Widget build(BuildContext context) {
    SystemChrome.setSystemUIOverlayStyle(_style);
    // TODO: implement build
    return MaterialApp(
      home: NativeStatefulWidget(),
      theme: ThemeData(primarySwatch: Colors.yellow),
    );
  }
}

class NativeStatefulWidget extends StatefulWidget {
  @override
  State<StatefulWidget> createState() {
    // TODO: implement createState
    return _NativeState();
  }
}

class _NativeState extends State<StatefulWidget> {
  static const String chanelName = "flutter.study.native/call_native";
  static const methodChanel = const MethodChannel(chanelName);
  static const methodName = "call_native_method";
  String _result = "";

  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return Scaffold(
      appBar: AppBar(
        title: Text("Native Page"),
      ),
      body: Center(
        child: Column(
          children: <Widget>[
            FlatButton(
                onPressed: () async {
                  String result =
                  await methodChanel.invokeMethod(methodName);
                  setState(() {
                    _result = result;
                  });
                },
                child: Text("调用Native")),
            Text("Native _result:  $_result"),
          ],
        ),
      ),
    );
  }
}
